package com.shop.admin.controller.paper;

import com.shop.admin.aop.Log;
import com.shop.admin.service.IPaperAssignService;
import com.shop.admin.validate.paper.PaperAssignCreateValidate;
import com.shop.admin.validate.paper.PaperAssignSearchValidate;
import com.shop.admin.validate.commons.IdValidate;
import com.shop.admin.validate.commons.PageValidate;
import com.shop.admin.vo.paper.PaperAssignDetailVo;
import com.shop.admin.vo.paper.PaperAssignListedVo;
import com.shop.common.core.AjaxResult;
import com.shop.common.core.PageResult;
import com.shop.common.validator.annotation.IDMust;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("${app.api-prefix}/paperAssign")
@Api(tags = "考试任务指派管理")
public class PaperAssignController {

    @Resource
    IPaperAssignService iPaperAssignService;

    @GetMapping("/list")
    @ApiOperation(value="考试任务指派列表")
    public AjaxResult<PageResult<PaperAssignListedVo>> list(@Validated PageValidate pageValidate,
                                                     @Validated PaperAssignSearchValidate searchValidate) {
        PageResult<PaperAssignListedVo> list = iPaperAssignService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @GetMapping("/detail")
    @ApiOperation(value="考试任务指派详情")
    public AjaxResult<PaperAssignDetailVo> detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        PaperAssignDetailVo detail = iPaperAssignService.detail(id);
        return AjaxResult.success(detail);
    }

    @Log(title = "考试任务指派新增")
    @PostMapping("/add")
    @ApiOperation(value="考试任务指派新增")
    public AjaxResult<Object> add(@Validated @RequestBody PaperAssignCreateValidate createValidate) {
        iPaperAssignService.add(createValidate);
        return AjaxResult.success();
    }

    @Log(title = "考试任务指派删除")
    @PostMapping("/del")
    @ApiOperation(value="考试任务指派删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        iPaperAssignService.del(idValidate.getId());
        return AjaxResult.success();
    }

}
